package com.mask.im.business.interception;
import com.mask.im.business.common.util.PageUtil;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * @author jian
 */
@Component
public class PageInterception implements HandlerInterceptor {

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
		String currentPage = request.getParameter("currentPage");
		String currentSize = request.getParameter("size");
		Integer page = Integer.valueOf(currentPage != null ? currentPage : "1");
		Integer size = Integer.valueOf(currentSize != null ? currentSize : "10");
		PageUtil.setPage(page,size);
		return true;
	}

	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
			PageUtil.removeThreadLocal();
	}
}
